package com.crm.service.impl;

import com.crm.context.BaseContext;
import com.crm.dto.ContractDto;
import com.crm.dto.ContractQueryPagePramDto;
import com.crm.mapper.ContractMapper;
import com.crm.pojo.Contract;
import com.crm.result.PageResult;
import com.crm.result.Result;
import com.crm.service.ContractService;
import com.crm.vo.ContractVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Service

public class ContractServiceImpl implements ContractService {
    @Autowired
    private ContractMapper contractMapper;

    @Override
    public PageResult queryContractList(ContractQueryPagePramDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<Contract> list = contractMapper.queryContractList(dto);
        Page<Contract> page = (Page<Contract>) list;
        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 根据id查询合同详情
     *
     * @param id
     * @return
     */
    @Override
    public Contract queryById(String id) {
        return contractMapper.queryById(id);
    }


    @Override
    public void addContact(ContractDto dto) {
        Contract contract = new Contract();
        contract.setCreateBy(String.valueOf(BaseContext.getCurrentId()));
        contract.setStatus("0");
        BeanUtils.copyProperties(dto, contract);
        contractMapper.addContract(contract);
    }


    @Override
    public Contract getById(String id) {
        return contractMapper.getById(id);
    }

    @Override
    public void updateContract(ContractDto dto) {
        Contract contract = new Contract();
        BeanUtils.copyProperties(dto, contract);
        contractMapper.updateContract(contract);
    }


}
